//
// Created by fanghr on 17-12-25.
//

#include "shm.h"

shm::shm(std::string name, size_t size) : shm_obj(boost::interprocess::open_or_create, name.data(),
                                                  boost::interprocess::read_write), name(name),
                                          map(shm_obj, boost::interprocess::read_write),
                                          mutex(boost::interprocess::open_or_create, name.data()) {
    shm_obj.truncate(size);
}

void *shm::get() {
    return map.get_address();
}

void shm::changeSize(size_t size) {
    shm_obj.truncate(size);
}

void shm::lock() {
    mutex.lock();
}

void shm::unlock() {
    mutex.unlock();+
}
